package com.itany.cloud.controller;

import com.itany.cloud.entity.User;
import com.itany.cloud.service.UserServiceClient;
import com.itany.cloud.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 石小俊
 */
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserServiceClient userService;

    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable Integer id) {
        return userService.findById(id);
    }

    @GetMapping
    public ResponseResult findAll() {
        return userService.findAll();
    }

    @PostMapping
    public ResponseResult addUser(User user) {
        return userService.addUser(user.getUsername(),user.getPassword());
    }

    @PutMapping
    public ResponseResult modifyUser(User user) {
        return userService.modifyUser(user.getId(),user.getUsername(),user.getPassword());
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteUser(@PathVariable Integer id) {
        return userService.removeUser(id);
    }

}
